Thread: Loading a Bitmap resource for OpenGL Texture[x]

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Loading a Bitmap resource for OpenGL Texture[x]

    I have been using this function to load Bitmaps for Textures in my OpenGL applications, taken from NeHe's tutorial:
    Code:
    AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
    {
    FILE *File=NULL; // File Handle
    if (!Filename) // Make Sure A Filename Was Given
    {
    return NULL; // If Not Return NULL
    }
    File=fopen(Filename,"r"); // Check To See If The File Exists
    if (File) // Does The File Exist?
    {
    fclose(File); // Close The Handle
    return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
    }
    return NULL; // If Load Failed Return NULL
    }
    I'm now dealing with a resource bitmap though, and I need something to replace Texture[0] = LoadBMP("bitmap.bmp").


    I tried TextureImage[0] = auxDIBImageLoad(MAKEINTRESOURCE(IDB_BITMAP1), which compiles but the App crashes,

    and TextureImage[0] = LoadImage(hInstance,MAKEINTRESOURCE(IDB_BITMAP1),I MAGE_BITMAP,0,0,LR_LOADFROMFILE);, where the compiler gives me a conversion error.

    What could I use as a replacement?

    Many people seen to be using this code to work with resources:
    Code:
    void LoadGLTextures()
    {
    // load bitmap from resource file
    HBITMAP bitmap = LoadBitmap(GetModuleHandle(NULL), 
    MAKEINTRESOURCE(IDB_BITMAP2));
    
    // setup 24 bits bitmap structure
    // works on 8 bits bitmaps also!
    
    BITMAPINFO info;
    BITMAPINFOHEADER header;
    header.biSize = sizeof(BITMAPINFOHEADER); 
    header.biWidth = 256; 
    header.biHeight = 256; 
    header.biPlanes = 1; 
    header.biBitCount = 24; 
    header.biCompression = BI_RGB;
    header.biSizeImage = 0; 
    header.biClrUsed = 0; 
    header.biClrImportant = 0; 
    info.bmiHeader = header;
    info.bmiColors->rgbRed = NULL;
    info.bmiColors->rgbGreen = NULL;
    info.bmiColors->rgbBlue = NULL;
    info.bmiColors->rgbReserved = NULL;
    
    // store bitmap data in a vector
    const int size = 256*256*3;
    unsigned char data[size]; 
    HDC hdc = GetDC(g_hWndRender);
    GetDIBits(hdc, bitmap, 0, 256, &data, &info, DIB_RGB_COLORS);
    ReleaseDC(g_hWndRender, hdc);
    
    // convert from BGR to RGB
    unsigned char buff;
    for(int i=0; i<256*256; i++)
    {
    buff = data[i*3];
    if(i>=3)
    {
    data[i*3] = data[i*3+2];
    data[i*3+2] = buff;
    }
    }
    
    // create one texture
    glGenTextures(1, &m_texture[0]);
    
    // select texture
    glBindTexture(GL_TEXTURE_2D, m_texture[0]);
    
    // SetTextureParameters
    
    // generate texture
    glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, &data);
    }
    But I'm still new to programming, and I'm having trouble figuring out how that will help me assigning the .bmp to TextureImage[], as in the non-resource code:

    Code:
    AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
    ...
    TextureImage[0] = LoadBMP("bitmap.bmp)
    Last edited by the dead tree; 08-25-2004 at 03:07 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with Bitmap Display
    By The Brain in forum Windows Programming
    Replies: 7
    Last Post: 03-23-2009, 05:33 AM
  2. Loading a bitmap (Without using glaux)
    By Shamino in forum Game Programming
    Replies: 7
    Last Post: 03-16-2006, 09:43 AM
  3. Loading BITMAP Resource
    By FWGaming in forum C++ Programming
    Replies: 1
    Last Post: 07-19-2005, 12:07 PM
  4. OpenGL -- Bitmaps
    By HQSneaker in forum Game Programming
    Replies: 14
    Last Post: 09-06-2004, 04:04 PM
  5. No one can seem to help me, loading bitmap
    By Shadow12345 in forum C++ Programming
    Replies: 7
    Last Post: 12-28-2002, 01:22 PM